﻿using System;

public abstract class Shape
{
    private String myId;
    private bool flag;
    public Shape (string s)
    {
        Id = s;
    }

    public String Id
    {
        get { return myId; } 
        set { myId = value; } 
    }
    public bool Flag
        { get { return flag; } set { flag = value; } }
    public abstract double Area
    { get; }
    public abstract bool isIegal();
    public virtual void Draw()
    {
        Console.WriteLine("Draw Shape Icon");
    }

    public override string ToString()
    {
        return Id + " Area=" + String.Format("{0:F2}",Area);
    }
}

public class Rectangle:Shape
{
    private double myWidth;
    private double myHeight;

    public Rectangle(int width,int height,string id):base(id)
    {
        myWidth = width;
        myHeight = height;
        if(isIegal())
        {
            Flag = true;
        }else
        {
            Flag = false;
            Console.WriteLine("ERROR");
        }
     

    }
    public override bool isIegal()
    {
       if(myWidth < 0 || myHeight < 0)
        {
            myWidth = 0;
            myHeight=0;
            return false;
        }else
        {
            return true;
        }
    }
    public override double Area
    {
        get 
        {
            if(Flag)
            {return myWidth * myHeight;}
            else
            { return 0; }
        }
    }

    public override void Draw()
    {
        if(Flag)
        Console.WriteLine("Draw Rectangle");
    }
}

public class Triangle:Shape
{
    private double len_a, len_b, len_c;
    public Triangle(double a,double b,double c,string id):base(id)
    {
        len_a = a;
        len_b = b;
        len_c = c;
        if (isIegal())
        {
            Flag = true;
        }
       else
        {
            Flag=false;
            Console.WriteLine("ERROR");
        }
    }

    public double Len_A
    { 
        get { return len_a; }
        set { len_a = value; } 
    }
    public double Len_B
    {
        get { return len_b; }
        set { len_b = value; }
    }

    public double Len_C
    {
        get { return len_c; }
        set { len_c = value; }
    }

    public override double Area
    {
        get
        {
            if (Flag)
            { 
            double p = (len_a + len_b + len_c) / 2;
            return Math.Sqrt(p * (p - len_b) * (p - len_c) * (p - len_a));
            }else
            {
                return 0;
            }
        }
    }
    public override bool isIegal()
    {
        if(len_a<0||len_b<0||len_c<0)
        {
            len_c=0;
            len_b=0;
            len_a=0;
            return false;
        }
        else if(len_a+len_b<len_c||len_b+len_c<len_a||len_b+len_c<len_a)
        {
            len_c = 0;
            len_b = 0;
            len_a = 0;
            return false;
        }else
        {
            return true;
        }
    }
    public override void Draw()
    {
        Console.WriteLine("Rraw Triangle");
    }
}

public class test
{
    public static void Main(string[] args)
    {
        Rectangle rectangle = new Rectangle(3, 4, "Rectangle");
        Console.WriteLine(  rectangle.Area);
        Triangle triangle = new Triangle(3, 4, 5, "Triangle");
        Console.WriteLine(triangle.Area);
    }
}

    